<?php 
define('IN_WONDERSHARE', true);
session_start();
header("Content-type:text/html;charset=utf-8");
require('../includes/init.php');
require('../conf/conf.php');
require ('./configs/site_config.php');
require('./classes/control/control_release.php');
class release
 {
	var $release_c;
	/**
	 * @ 构造函数,实例化releaseControl
	 * @ __construct
	 */
 	
	public function __construct()
	{
		
		$this->release_c = new releaseControl();
	}
	
	/**
	* @函数index,返回默认列表
	* @param  NULL
	* @return  string
	*/
	function index()
	{
	  $url_info = $release_info = array();
		//分页处理
	  $web	= !empty($_POST['web']) ? trim($_POST['web']) : trim($_GET['web']);
	  $url	= !empty($_POST['url']) ? trim($_POST['url']) : trim($_GET['url']);
	  $type	= !empty($_POST['type']) ? trim($_POST['type']) : trim($_GET['type']);
	  $page = 1;
      if (!empty($_REQUEST['page'])) {
		  $page = (int)$_REQUEST['page'];
      }
      
	  if($web)
	  {
         $url_info = $this->release_c->get_url_info($page,2,$url,$web);
	  	 $release_info = $this->release_c->get_release_info('list_s',$url_info['page_info']['start'],20,$url,$web);
	  }
	  else
	  {
	  	$url_info = $this->release_c->get_url_info($page,1,$url);
	  	$release_info = $this->release_c->get_release_info('list',$url_info['page_info']['start'],20,$url);
	  }
      $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
      $GLOBALS['smarty']->assign('release_info',$release_info );
      $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
	  $GLOBALS['smarty']->assign('url',$url );
	  $GLOBALS['smarty']->assign('web',$web );
	  $GLOBALS['smarty']->assign('type',$type );
	  $GLOBALS['smarty']->display('release_index.htm'); 
	  
	}
 	
	/**
	* @函数released_edit//增加，修改
	* @param  NULL
	* @return  string
	*/
	public function add_edit()
	{
		
			
 		$array = array
 		(
	 		 'web' => trim($_POST['web']),
	 		 'contents' => trim($_POST['contents']),
			 'backup' => trim($_POST['backup'])
 		);	
 		
	 	if($_REQUEST['act'] == 'add')
	 	{
		   if($_POST['sub_from'])
		   {
	
			    $affect = $this->release_c->operate_release('add',0,$array);

		   }
		   
		   $site = array(
		   		'wondershare.com'	=> 4,
		   		'images.wondershare.com'	=> 4,
				'store.wondershare.com'	=> 4,
		   		'pop.wondershare.com'	=> 4,
				'sameshow.com'=> 4,
				'photo.wondershare.com'	=> 4,
				'software-couponcode.com'	=> 4,
				'wondershare.software-couponcode.com'	=> 4,
				'iskysoft.software-couponcode.com'=>4,
				'aimersoft.software-couponcode.com'=>4,
				'images.software-couponcode.com'=>4,
				'friendin.ws'	=> 5,
				'images.friendin.ws'	=> 5,
				'wondershare.jp'	=> 9,
				'anypdftools.com'	=> 10,
				'cn.anypdftools.com'	=> 10,
				'de.anypdftools.com'	=> 10,
				'br.anypdftools.com'	=> 10,
				'jp.anypdftools.com'	=> 10,
				'it.anypdftools.com'	=> 10,
				'es.anypdftools.com'	=> 10,
				'ru.anypdftools.com'	=> 10,
				'tw.anypdftools.com'	=> 10,
				'kr.anypdftools.com'	=> 10,
				'resource.anypdftools.com'	=> 10,
				'store.anypdftools.com'	=> 10,
		   		'fr.anypdftools.com'=> 10,
		   		'applemacvideo.com'	=> 35,
				'de.applemacvideo.com'	=> 35,
				'br.applemacvideo.com' => 35,
				'fr.applemacvideo.com' => 35,
				'jp.applemacvideo.com' => 35,
				'es.applemacvideo.com' => 35,
				'cn.applemacvideo.com' => 35,
				'ru.applemacvideo.com' => 35,
				'tw.applemacvideo.com' => 35,
				'kr.applemacvideo.com' => 35,
			     'iskysoft.net'=> 36,
			    'iskysoft.com'	=> 36,
		   		'pop.iskysoft.com'	=> 36,
		   		'images.iskysoft.com'	=> 36,	
				'aimersoft.com'	=> 37,
				'aimersoft.de'=> 37,
		   		'images.aimersoft.com'	=> 37,	   
		   		'pop.aimersoft.com'	=> 37,	
				'daniusoft.com'=> 37,
				'ppt-to-dvd.com'=> 37,
				'acoolsoft.com'=> 37,
				'aimersoft.net'=> 37,
				'aimersoft.jp'=> 37,
				'aimersoft.fr'=> 37,
				'aimersoft.it'=> 37,
				'aimersoft.br'=> 37,
				'aimersoft.es'=> 37,
				'aimersoft.cn'=> 37,
				'aimersoft.tw'=> 37,
				'aimersoft.ru'=> 37,
				'aimersoft.kr'=> 37,
			  	'm.wondershare.com'	=> 56,
				'support.wondershare.com' => 65,
				'wondershare.com.mx'	=> 66,
				'wondershare.com.br'	=> 67,
				'store.wondershare.com.br'	=> 67,
				'images.wondershare.com.br'	=> 67,
				'wondershare.it'	=> 67,
				'support.iskysoft.com'	=> 127,
		   		'support.aimersoft.com'	=> 147
	
		   );

		   $GLOBALS['smarty']->assign('AID',     $_SESSION['AID']);
		   $GLOBALS['smarty']->assign('MPower',     explode(',',$_SESSION['MPower']));
		   $GLOBALS['smarty']->assign('site',     $site);
		   $GLOBALS['smarty']->assign('title',     '网站');
		   $GLOBALS['smarty']->assign('form_act',     'add');
		   $GLOBALS['smarty']->display('release_info.htm');
		}
	}
	/**
	* @函数backup//备份数据库
	* @param  NULL
	* @return  string
	*/
	function backup()
	{
	    $this->release_c->release_backup();
	}
	
 	function rsync(){
 		
	    $affect = $this->release_c->rsync_c();
	 
		if($affect == 1)
		{
			$msg = '发布成功';
			//发布cdn文件
			if (in_array(trim($_REQUEST['web']), $GLOBALS['cdn_www']) ) {
				
				$msg =  trim( $this->release_c->initCdnFileName(trim($_REQUEST['web'])) );
				$msg = str_replace('||', '<br>', $msg);
				
				$msg = empty($msg) ? '发布成功,今天更新文件没有记录！' : $msg;
				
			}
			echo $msg;
			exit;
			
		}else{
			echo  "<script>alert('{$affect}');window.location.href='/wondershare/release.php'</script>";
			exit;			 		
		}
	}
 }
$action    = $_REQUEST['action']; 
$release   = new release;
if(method_exists($release, $action)) 
{
	$release->$action();
}else{
	$release->index();
}
	
?>
